﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ircclient
{
    public partial class FormMain : Form
    {
        public Thread connection;
        public FormMain()
        {
            InitializeComponent();
        }

        private void ConnectButton1_Click(object sender, EventArgs e)
        {

            Server Serv = new Server("epicnet.ru", 6667, this);
            connection = new Thread(new ThreadStart(Serv.Connect));
            connection.Start();
            connection.IsBackground = true;
        }
        public void AddNewSwitchButton(string buttonName)
        {
            ToolStripButton but = new ToolStripButton(buttonName);
            
            but.TextAlign = ContentAlignment.MiddleLeft;
            but.Click += new EventHandler(switch_Click);
            if (swithBar.InvokeRequired)
                swithBar.Invoke(new Action<ToolStripButton>((s) => swithBar.Items.Add(s)), but);
            else
                swithBar.Items.Add(but);
            
        }

        void switch_Click(object sender, EventArgs e)
        {
            ToolStripButton b = (ToolStripButton)sender;
            foreach (FormChat form in this.MdiChildren)
            {
                if (form.Text == b.Text)
                {
                    form.View();
                }
            }
        }
        public void DelSwitchButton(string buttonName)
        {
            if (swithBar.InvokeRequired)
                swithBar.Invoke(new Action<string>((s) => DelSwitchButton(s, true)), buttonName);
            else
                DelSwitchButton(buttonName, true);
        }

        private void DelSwitchButton(string buttonName, bool f)
        {
            for (int i = 0; i < swithBar.Items.Count; i++)
            {
                if (swithBar.Items[i].Text == buttonName)
                    swithBar.Items.RemoveAt(i);
            }

        }
    }
}
